package com.java.repository.bank2;

import com.java.entity.bank2.Bank2UserAccount;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Repository
public interface Bank2UserAccountRespository extends JpaRepository<Bank2UserAccount, Long> {

    @Transactional(rollbackFor = Exception.class)
    @Modifying(clearAutomatically = true)
    @Query(value = "update user_account set amount=?2 where account_id =?1 ", nativeQuery = true)
    void updateAmount(Long accountId, BigDecimal amount);

    @Query(value = "select  * from user_account where account_id=?1 ", nativeQuery = true)
    Bank2UserAccount queryByAccountId(Long accountId);
}
